import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    TreeNode() {
    }

    TreeNode(int val) {
        this.val = val;
    }

    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}

public class Solution {
    public List<Integer> inorderTraversal(TreeNode root) {
        if(root==null){
            return null;
        }
        List<Integer> arr=new ArrayList();
        Stack<TreeNode> stack=new Stack();
        TreeNode cur=root;
        while(cur!=null){
            stack.push(cur);
            cur=cur.left;
        }
        while(cur!=null||!stack.isEmpty()){
            while(cur!=null){
                arr.add(cur.val);
                cur=stack.pop();
                if(cur.right!=null){
                    stack.push(cur.right);
                }
            }

        }
        Collection.reverse(arr);

        return arr;
    }
}